package com.mike.swt.util;

import org.eclipse.swt.widgets.Shell;

public class ShellUtil {
	
	public static void setCenter(Shell shell) {
		if(null == shell) return;
		int w = shell.getMonitor().getClientArea().width;
		int h = shell.getMonitor().getClientArea().height;
		int x = shell.getSize().x;
		int y = shell.getSize().y;
		shell.setLocation(( w - x ) / 2, ( h - y ) / 2);
	}
	
	public static void setCenter(Shell sub, Shell base) {
		if(null == sub || null == base) return;
		sub.setLocation(
				base.getLocation().x + (base.getSize().x - sub.getSize().x) / 2, 
				base.getLocation().y + (base.getSize().y - sub.getSize().y) / 2
				);
	}
	
}
